﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ras2ClassLib;

namespace Ras2
{
	public partial class NewListDlg : Form
	{
		public NewListDlg()
		{
			InitializeComponent();
		}

		private ListViewItem GetListViewItem(Lag song)
		{
			ListViewItem item = new ListViewItem(song.Name);

			item.ImageIndex = 0;

			item.Tag = song;

			return item;
		}

		private void OnLoad(object sender, EventArgs e)
		{
			if (!this.DesignMode)
			{
				m_listSongs.Items.Clear();
				LagDoc doc = new LagDoc();
				LagCollection songs = doc.GetAllLag();

				foreach (Lag song in songs)
				{
					m_listSongs.Items.Add(GetListViewItem(song));
				}
			}
		}

		private void OnAddSong(object sender, EventArgs e)
		{
			if (m_listSongs.SelectedItems.Count == 1)
			{
				ListViewItem listViewItem = m_listSongs.SelectedItems[0];
				Lag song = (Lag)listViewItem.Tag;

				m_listHitlist.Items.Add(GetListViewItem(song));
			}
			else
			{
				MessageBox.Show("Þú verður að velja lag");
			}
		}

		private void OnRemoveSong(object sender, EventArgs e)
		{
			if (m_listHitlist.SelectedItems.Count == 1)
			{
				ListViewItem listViewItem = m_listHitlist.SelectedItems[0];
				Lag song = (Lag)listViewItem.Tag;

				m_listHitlist.Items.Remove(listViewItem);
			}
			else
			{
				MessageBox.Show("Þú verður að velja lag");
			}
		}
	}
}
